package top.glike.ssl.auto.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.glike.ssl.auto.domain.SslServer;
import top.glike.ssl.auto.mapper.SslServerMapper;
import top.glike.ssl.auto.service.ISslServerService;

import java.util.Date;
import java.util.List;

/**
 * 服务器管理Service业务层处理
 *
 * @author Sophia
 * @date 2025-10-12
 */
@Service
public class SslServerServiceImpl implements ISslServerService {

    @Autowired
    private SslServerMapper sslServerMapper;

    /**
     * 查询服务器管理
     *
     * @param id 服务器管理主键
     * @return 服务器管理
     */
    @Override
    public SslServer selectSslServerById(Long id) {
        return sslServerMapper.selectSslServerById(id);
    }

    /**
     * 查询服务器管理列表
     *
     * @param sslServer 服务器管理
     * @return 服务器管理
     */
    @Override
    public List<SslServer> selectSslServerList(SslServer sslServer) {
        return sslServerMapper.selectSslServerList(sslServer);
    }

    /**
     * 新增服务器管理
     *
     * @param sslServer 服务器管理
     * @return 结果
     */
    @Override
    public int insertSslServer(SslServer sslServer) {
        sslServer.setUpdatedTime(new Date());
        sslServer.setCreatedTime(sslServer.getUpdatedTime());
        return sslServerMapper.insertSslServer(sslServer);
    }

    /**
     * 修改服务器管理
     *
     * @param sslServer 服务器管理
     * @return 结果
     */
    @Override
    public int updateSslServer(SslServer sslServer) {
        sslServer.setUpdatedTime(new Date());
        return sslServerMapper.updateSslServer(sslServer);
    }

    /**
     * 批量删除服务器管理
     *
     * @param ids 需要删除的服务器管理主键
     * @return 结果
     */
    @Override
    public int deleteSslServerByIds(Long[] ids) {
        return sslServerMapper.deleteSslServerByIds(ids);
    }

    /**
     * 删除服务器管理信息
     *
     * @param id 服务器管理主键
     * @return 结果
     */
    @Override
    public int deleteSslServerById(Long id) {
        return sslServerMapper.deleteSslServerById(id);
    }

    @Override
    public SslServer saveSslServer(SslServer sslServer) {
        if (sslServer.getId() != null) {
            sslServer.setUpdatedTime(new Date());
            sslServerMapper.updateSslServer(sslServer);
        } else {
            sslServer.setUpdatedTime(new Date());
            sslServer.setCreatedTime(sslServer.getUpdatedTime());
            sslServerMapper.insertSslServer(sslServer);
        }
        return sslServer;
    }
}
